package com.bjpowernode.config.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * spring容器提供者
 */
@Component
public class ApplicationContextProvider implements ApplicationContextAware {

    // 静态变量
    private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        // 将容器对象赋值给变量
        ApplicationContextProvider.applicationContext = applicationContext;
    }

    // 普通的静态方法
    public static ApplicationContext getApplicationContext() {
        return ApplicationContextProvider.applicationContext;
    }

}
